home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWBmpShp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  7.0 KB  |  250 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWBmpShp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWBMPSHP_H
  13. #include "FWBmpShp.h"
  14. #endif
  15.  
  16. #ifndef SLGRGLOB_H
  17. #include "SLGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef SLRENDER_H
  29. #include "SLRender.h"
  30. #endif
  31.  
  32. // ----- Foundation Includes -----
  33.  
  34. #ifndef FWSTREAM_H
  35. #include "FWStream.h"
  36. #endif
  37.  
  38. #ifndef FWDEBUG_H
  39. #include "FWDebug.h"
  40. #endif
  41.  
  42. //========================================================================================
  43. // File scope definitions
  44. //========================================================================================
  45.  
  46. #if defined(__MWERKS__) && GENERATING68K
  47. // A hack to work around a bug
  48. #pragma import list somGetGlobalEnvironment
  49. #endif
  50.  
  51. #ifdef FW_BUILD_MAC
  52. #pragma segment fwgraphxshape
  53. #endif
  54.  
  55. //========================================================================================
  56. //    CLASS FW_CBitmapShape
  57. //========================================================================================
  58.  
  59. FW_DEFINE_CLASS_M1(FW_CBitmapShape, FW_CBoundedShape)
  60. FW_DEFINE_AUTO(FW_CBitmapShape)
  61.  
  62. // This class is archivable, but we provide the archiving implementation in a separate
  63. // translation unit in order to enable deadstripping of the archiving-related code
  64. // in parts that do not use archiving with this class.
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    FW_CBitmapShape::FW_CBitmapShape
  68. //----------------------------------------------------------------------------------------
  69.  
  70. FW_CBitmapShape::FW_CBitmapShape(const FW_CBitmapShape& other) :
  71.     FW_CBoundedShape(other),
  72.     fSrcRect(other.fSrcRect),
  73.     fBitmap(other.fBitmap)
  74. {
  75.     FW_END_CONSTRUCTOR
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    FW_CBitmapShape::FW_CBitmapShape
  80. //----------------------------------------------------------------------------------------
  81.  
  82. FW_CBitmapShape::FW_CBitmapShape(FW_CBitmap bitmap, const FW_CRect& dstRect) :
  83.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  84.     fBitmap(bitmap)
  85. {
  86.     short width, height,rowBytes, pixelSize;
  87.     
  88.     fBitmap.GetBitmapInfo(width, height, rowBytes, pixelSize);
  89.     fSrcRect.SetInt(0, 0, width, height);
  90.  
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CBitmapShape::FW_CBitmapShape
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CBitmapShape::FW_CBitmapShape(FW_CBitmap bitmap, const FW_CRect& srcRect, const FW_CRect& dstRect) :
  99.     FW_CBoundedShape(dstRect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  100.     fSrcRect(srcRect),
  101.     fBitmap(bitmap)
  102. {
  103.     FW_END_CONSTRUCTOR
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    FW_CBitmapShape::FW_CBitmapShape
  108. //----------------------------------------------------------------------------------------
  109.  
  110. FW_CBitmapShape::FW_CBitmapShape(FW_CReadableStream& stream) :
  111.     FW_CBoundedShape(stream)
  112. {
  113.     stream.Read(&fSrcRect, 4);
  114.     stream >> fBitmap;
  115.     
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_CBitmapShape::~FW_CBitmapShape
  121. //----------------------------------------------------------------------------------------
  122.  
  123. FW_CBitmapShape::~FW_CBitmapShape()
  124. {
  125.     FW_START_DESTRUCTOR
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    FW_CBitmapShape::operator=
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CBitmapShape& FW_CBitmapShape::operator=(const FW_CBitmapShape& other)
  133. {
  134.     if (this != &other)
  135.     {
  136.         FW_CBoundedShape::operator=(other);
  137.         
  138.         fBitmap = other.fBitmap;
  139.         fSrcRect = other.fSrcRect;
  140.     }
  141.     
  142.     return *this;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CBitmapShape::Copy
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CShape* FW_CBitmapShape::Copy() const
  150. {
  151.     return FW_NEW(FW_CBitmapShape, (*this));
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    FW_CBitmapShape::Render
  156. //----------------------------------------------------------------------------------------
  157.  
  158. void FW_CBitmapShape::Render(FW_CGraphicContext& gc) const
  159. {
  160.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  161.         gc,
  162.         fBitmap,
  163.         fSrcRect,
  164.         fRect,
  165.         GetRenderVerb(),
  166.         fInk);
  167.     FW_FailOnEvError(gc.GetEnvironment());
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_CBitmapShape::RenderBitmap
  172. //----------------------------------------------------------------------------------------
  173.  
  174. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  175.                                     FW_CBitmap bitmap,
  176.                                     const FW_CRect& dstRect,
  177.                                     const FW_CInk& ink)
  178. {
  179.     FW_CRect srcRect;
  180.     bitmap.GetBitmapBounds(srcRect);
  181.  
  182.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  183.         gc,
  184.         bitmap,
  185.         srcRect,
  186.         dstRect,
  187.         FW_kFill,
  188.         ink);
  189.     FW_FailOnEvError(gc.GetEnvironment());
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_CBitmapShape::RenderBitmap
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void FW_CBitmapShape::RenderBitmap(FW_CGraphicContext& gc,
  197.                                     FW_CBitmap bitmap,
  198.                                     const FW_CRect& srcRect, 
  199.                                     const FW_CRect& dstRect,
  200.                                     const FW_CInk& ink)
  201. {
  202.     FW_PrivRenderBitmap(gc.GetEnvironment(),
  203.         gc,
  204.         bitmap,
  205.         srcRect,
  206.         dstRect,
  207.         FW_kFill,
  208.         ink);
  209.     FW_FailOnEvError(gc.GetEnvironment());
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CBitmapShape::GetGeometry
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void FW_CBitmapShape::GetGeometry(FW_CBitmap& bitmap, 
  217.                                 FW_CRect& srcRect, 
  218.                                 FW_CRect& dstRect) const
  219. {
  220.     bitmap = fBitmap;
  221.     srcRect = fSrcRect;
  222.     dstRect = fRect;
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. //    FW_CBitmapShape::SetGeometry
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void FW_CBitmapShape::SetGeometry(const FW_CBitmap& bitmap, 
  230.                                 const FW_CRect& srcRect, 
  231.                                 const FW_CRect& dstRect)
  232. {
  233.     fBitmap = bitmap;
  234.     fSrcRect = srcRect;
  235.     fRect = dstRect;
  236. }
  237.  
  238. //----------------------------------------------------------------------------------------
  239. //    FW_CBitmapShape::Flatten
  240. //----------------------------------------------------------------------------------------
  241.  
  242. void FW_CBitmapShape::Flatten(FW_CWritableStream& stream) const
  243. {
  244.     FW_CBoundedShape::Flatten(stream);
  245.     stream.Write(&fSrcRect, 4);
  246.     Environment* ev = somGetGlobalEnvironment();
  247.     stream << fBitmap;
  248. }
  249.  
  250.